#include "DictServer.hpp"

void Usage(std::string proc)
{
    std::cerr << "Usage: " << proc << " localport" << std::endl;
}
// 不需要知道sever端的ip，因为用了INADDR_ANY，默认所有端口都会打开
int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        Usage(argv[0]);
        exit(0);
    }
    uint16_t serverport = std::stoi(argv[1]);
    EnableConsoleLogStrategy();
    Dictionary dict("./dict.txt");
    std::unique_ptr<UdpServer> server = std::make_unique<UdpServer>(serverport, 
                [&dict](std::string &word, const std::string &whoip, uint16_t whoport)->std::string 
                {
                    return dict.Translate(word, whoip, whoport);
                });
    LOG(Loglevel::DEBUG) << "server创建成功" ;
    server->Init();
    server->Start();
}